//
//  UserMovieViewController.m
//  product_B
//
//  Created by lanou on 16/6/3.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "UserMovieViewController.h"
#import "MovieMainModel.h"
#import "MovieDetailViewController.h"
@interface UserMovieViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *modelArray;
@end

@implementation UserMovieViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self requestWork];
    self.modelArray = [NSMutableArray array];
    self.navigationItem.title = @"电影收藏";
    self.navigationController.navigationBar.hidden = NO;
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight+49)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    self.navigationController.navigationBarHidden = NO;
}
- (void)requestWork{
    [RequestManager initWithUrlString:[NSString  stringWithFormat:@"http://v3.wufazhuce.com:8000/api/othercollection/%@/newer/5/0",_modelID] requestType:@"GET" parDic:nil finishBlock:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        NSArray *array = dic[@"data"];
        for (NSDictionary *dataDic in array) {
            MovieMainModel *model = [[MovieMainModel alloc]init];
            [model setValuesForKeysWithDictionary:dataDic];
            [self.modelArray addObject:model];
        }
        [self.tableView reloadData];
    } errorBlock:nil];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.modelArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    MovieMainModel *model = self.modelArray[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:@"摄影机.png"];
    cell.textLabel.text = model.title;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     MovieMainModel *model = self.modelArray[indexPath.row];
    MovieDetailViewController *movieVC = [[MovieDetailViewController alloc]init];
    movieVC.movieMainModel = model;
    [self.navigationController pushViewController:movieVC animated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
